package com.atguigu.dw.gamallcanal

import java.util.Properties

import com.atguigu.constan.ConstanVal
import org.apache.kafka.clients.producer.{KafkaProducer, ProducerConfig, ProducerRecord}

/**
 * description ：kafka 工具类
 * author      ：剧情再美终是戏 
 * mail        : 13286520398@163.com
 * date        ：Created in 2020/2/14 15:00
 * modified By ：
 * version:    : 1.0
 */
object MyKafkaUtil {

  // 创建 kafka 生产者
  val properties = new Properties()
  properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, ConstanVal.KAFKA_CLIENT_ADRESS)
  properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer")
  properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer")
  val producer = new KafkaProducer[String, String](properties)

  /**
   * kafka 生产数据方法
   *
   * @Author 剧情再美终是戏
   * @Date 2020/2/14 15:16
   * @param topic
   * @param value
   * @return void
   * @Version 1.0
   **/
  def send(topic: String, value: String): Unit = {
    producer.send(new ProducerRecord[String, String](topic, value))
  }
}
